#!/usr/bin/python
# build_native.py
# Build native codes

import os

CWD = os.path.dirname(__file__)
UPX_EXEC = os.path.join(CWD, 'upx.exe')
ARMEABIS = [ 'libcocos2dlua.so' ]

def find_so(ndk_work_dir):
    files = []
    libs = [ 'libs/armeabi', 'libs/armeabi-v7a' ]
    for lib in libs:
        root = os.path.join(ndk_work_dir, lib)
        for abi in ARMEABIS:
            file = os.path.join(root, abi)
            if os.path.isfile(file):
                files.append(file)
    return files

def do_upx(f):
    commond = '%s %s' % (UPX_EXEC, f)
    os.system(commond)

def do_ndk_build(ndk_work_dir):
    files = find_so(ndk_work_dir)
    for f in files:
        do_upx(f)
    pass

if __name__ == '__main__':
    do_ndk_build('D:\\git\\sszg_new_crc\\client_core\\frameworks\\runtime-src\\proj.android')
    pass